package com.pointi.emoEngine;

final class calc_feat
{
	double min ;
	double max ; 
	double mean ;
	double median ;
	double var ;
	double std ;
	double range ;
}

public class DSP_Define
{
	DSP_Define() {
	}
	
	public void sort(double [] x, int var_num)
	{
		double tmp ;
		for (int m = 0 ; m < var_num ; m++)
		{
			for (int n = 0 ; n < var_num ; n++)
			{
				if (x[m] > x[n])
				{
					tmp = x[m] ;
					x[m] = x[n] ;
					x[n] = tmp ;
				}
			}
		}
	}
	public calc_feat CALC_FEAT(double [] x, int var_num)
	{
		double tmp ;
		double [] arr ;
		calc_feat result = new calc_feat() ;

		tmp = 0 ;
		arr = new double [var_num] ;
		for (int m = 0 ; m < var_num ; m++)
		{
			arr[m] = x[m] ; 
			tmp += arr[m] ;		
		}
		result.mean = tmp / var_num ;
		tmp = 0 ;
		for (int m = 0 ; m < var_num ; m++) { tmp += (arr[m] - result.mean) * (arr[m] - result.mean) ; }
		result.var = tmp / (var_num - 1) ;
		result.std = Math.sqrt(tmp / (var_num -1)) ;
		sort(arr, var_num) ;
		result.min = arr[var_num - 1] ;
		result.max = arr[0] ;
		result.range = result.max - result.min ;
		result.median = arr[(int)Math.floor(var_num/2.0)] ;
		if (2 * Math.floor(var_num / 2.0) == var_num)
		{
			result.median = (arr[(int)Math.floor(var_num/2.0)] + arr[(int)Math.floor(var_num/2.0)-1]) / 2 ;	
		}
		return result ;
	}
}